import { defineStore } from 'pinia';
interface AuthState {
    token?: string;
    userInfo: Record<string, any>;
    safeInfo: Record<string, any>;
}
export const userAppInfo = defineStore({
    id: 'user-info',
    state: (): AuthState => ({
        token: undefined,
        userInfo: {},
        safeInfo: {}
    }),
    getters: {
        isLogin(): boolean {
            return this.token !== undefined;
        },
    },
    actions: {
        // 退出登录
        layout() {
            this.token = undefined;
            this.userInfo = {};
            uni.redirectTo({
                url: "/pages/login/index"
            })
        },
        // 记录 手机安全距离
        safeChange(data: any) {
            this.safeInfo = data
        },
        baseChange(info: any) {
            this.token = info.token;       
            this.userInfo = {
                nickName: info.nickName,
                avatar: info.avatar,
                mobile: info.mobile,
            };
        }
    },
    // 本地持久化存储
    persist: {
        storage: {
            getItem: uni.getStorageSync,
            setItem: uni.setStorageSync,
        },
    },
})